print 'popolo configbknloc_formule'
GO
INSERT INTO CONFIGBKNLOC_FORMULE (COD_LOCALE, CODSCO)
 (SELECT '*', CODSCO FROM FORMULE)
GO
PRINT 'POPOLO CONFIGLINEE_FORMULE'
GO
DECLARE @COD_CFG_LINEA CHAR(10), @MACROREGIONE CHAR(4)
SET @MACROREGIONE='SICI'
DECLARE CURSORE CURSOR FOR SELECT COD_CFG_LINEA FROM CONFIGLINEE CL
	INNER JOIN LINEE L ON L.CODLIN=CL.CODLIN
	INNER JOIN MACROREGIONI M ON M.MACROREGIONE=L.MACROREGIONE
	WHERE M.MACROREGIONE=@MACROREGIONE
OPEN CURSORE
FETCH NEXT FROM CURSORE INTO @COD_CFG_LINEA
WHILE @@FETCH_STATUS =0
BEGIN
	INSERT INTO CONFIGLINEE_FORMULE (COD_CFG_LINEA, CODSCO)
		SELECT @COD_CFG_LINEA, CODSCO FROM CONFIGMACROREGIONI_FORMULE WHERE MACROREGIONE=@MACROREGIONE
	FETCH NEXT FROM CURSORE INTO @COD_CFG_LINEA
END
CLOSE CURSORE
DEALLOCATE CURSORE
GO
